#include "utils.h"
#include <QPlainTextEdit>

Utils::Utils(QObject *parent) :
    QObject(parent)
{

}

void Utils::limitTextEdit(QPlainTextEdit * te, int limit)
{
    if (te->toPlainText().length() > limit){
        QString text = te->toPlainText();
        text.chop(text.length() - limit); // Cut off at 300 characters
        te->setPlainText(text); // Reset text

        // This code just resets the cursor back to the end position
        // If you don't use this, it moves back to the beginning.
        // This is helpful for really long text edits where you might
        // lose your place.
        QTextCursor cursor = te->textCursor();
        cursor.setPosition(te->document()->characterCount() - 1);
        te->setTextCursor(cursor);
    }
}
